﻿using System;
using TechTalk.SpecFlow;
using WatiN.Core;

namespace Testicide_BDD.Steps
{
    [Binding]
    public class ManagingScenariosSteps
    {
        private IE _browser;
        public ManagingScenariosSteps()
        {
            _browser = new IE();
        }

        [Given(@"I am on the feature page of Module number (.*)")]
        public void GivenIAmOnTheFeaturePageOfModuleNumber(int p0)
        {
            _browser.GoTo("http://localhost:57662/Module/Details/"+p0);
        }

        [Given(@"I am on the scenarios page")]
        public void GivenIAmOnTheScenariosPage()
        {
            _browser.GoTo("http://localhost:57662/Module/Details/" + 1);
            var link = _browser.Link("detailsFeature_" + 1);
            link.Click();
            _browser.GoTo("http://localhost:57662/Scenario/Tool_box");
        }

        [Given(@"I clicked on item number (.*) from the tool box")]
        public void GivenIClickedOnItemNumberFromTheToolBox(int p0)
        {
            _browser.GoTo("http://localhost:57662/Module/Details/" + 1);
            var link = _browser.Link("detailsFeature_" + 1);
            link.Click();
            _browser.GoTo("http://localhost:57662/Scenario/Tool_box");
            var li = _browser.ListItem(p0+"");
            li.Click();
        }

        [When(@"I click on the Feature number (.*)")]
        public void WhenIClickOnTheFeatureNumber(int p0)
        {
            var link = _browser.Link("detailsFeature_"+p0);
            link.Click();
        }

        [When(@"I click on item number (.*) from the tool box")]
        public void WhenIClickOnItemNumberFromTheToolBox(int p0)
        {
            var li = _browser.ListItem(p0 + "");
            li.Click();
        }

        [When(@"I press Run Test button number (.*)")]
        public void WhenIPressRunTestButtonNumber(int p0)
        {
            var btn = _browser.Button(p0+"");
            btn.Click();
        }

        [Then(@"I should be on the scenarios page")]
        public void ThenIShouldBeOnTheScenariosPage()
        {
            _browser.GoTo("http://localhost:57662/Scenario/Tool_box");
        }

        [Then(@"I should see ""(.*)"" on my workspace")]
        public void ThenIShouldSeeOnMyWorkspace(string p0)
        {
            _browser.TableCell(p0 + "");
        }

        [Then(@"I should see the result on my workspace")]
        public void ThenIShouldSeeTheResultOnMyWorkspace()
        {
            _browser.Para("result+2");
        }

        [AfterScenario]
        public void ff()
        {
            _browser.Dispose();
        }
    }
}
